<?php
require_once('common.inc.php');
require_once(_INC_PATH.'database.php');
require_once(_INC_PATH.'captcha.inc');

$cmd = @$_REQUEST['cmd'];
if($cmd == 'ajaxchange'){
	ajaxchange();
	die;
}

function ajaxchange(){
	$db = new database();
	$ids = $_POST['ids'];
	$tempArr = explode('||',$ids);
	$res_id = $tempArr[0];
	$est_id = $tempArr[1];
	$now = date("Y-m-d H:i:s");
	$sql = "update tbl_response set is_read='1' where id='$res_id'";
	$db->query($sql);
	$sql = "update tbl_estimate set update_time='$$now' where id='$est_id'";
	$db->query($sql);
	die;
}

if(!checkIsLogin())header("Location: /login.php");
$userName = _getcookie("user_name");
$userId = _getcookie("id");
$db = new database();
$sql = "select tr.id,tr.estimate_id,tr.content,te.cor_id from tbl_response tr left join tbl_estimate te on tr.estimate_id=te.id  where tr.is_read='0' and tr.user_id='$userId'";

$db->setQuery($sql);
$data = $db->loadAssocList();
$total = count($data);
if($total > 0){
	$res_color = "#FF9900";
}else{
	$res_color = "#999999";
}
if(!empty($data)){
	foreach($data as $key=>$value)
	{
		$content = preg_replace("#&lt;img src=&quot;"._HOST_ROOT."/images/face/(\d){1,2}.gif&quot; /&gt;#isU",'',$value['content']);
		$content = content_replace($content,'','','');
		$data[$key]['content'] = mb_substr($content,0,20,"utf8");
	}
}
$smarty->assign("res_color",$res_color);
$smarty->assign("res_total",$total);
$smarty->assign("rows",$data);


$smarty->assign("userName",$userName);
Display("mypage.tpl");


?>